package com.beiye.drivertransport.curriulum;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.alibaba.fastjson.JSON;
import com.android.frame.view.linearlistview.LinearListView;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.SubActivity.HaveTestActivity;
import com.beiye.drivertransport.activity.TwoBaseAty;
import com.beiye.drivertransport.adapter.HaveTestAdapter;
import com.beiye.drivertransport.bean.HaveTestBean;
import com.beiye.drivertransport.bean.LoginUserBean;
import com.beiye.drivertransport.http.Login;
import com.beiye.drivertransport.utils.UserManger;
import com.beiye.drivertransport.utils.Utils;
import com.githang.statusbar.StatusBarCompat;

import java.util.List;


import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

public class OnlineEducationRecordActivity extends TwoBaseAty {

    LinearListView listview_havetest;

    ImageView img_online_back;
    private HaveTestAdapter messageHTApt;

    @Override
    public int getLayoutId() {
        return R.layout.activity_online_education_record;
    }


    public void onClick(View view) {
        if (view.getId() == R.id.img_online_back) {
            finish();
        }

    }
    @Override
    public void initData() {
        listview_havetest = (LinearListView) findViewById(R.id.listview_online1);
        img_online_back = (ImageView) findViewById(R.id.img_online_back);

        StatusBarCompat.setStatusBarColor(this, Color.parseColor("#1F80C4"));
        //已考监听
        listview_havetest.setOnItemClickListener(new LinearListView.OnItemClickListener() {
            @Override
            public void onItemClick(LinearListView parent, View view, int position, long id) {
                if (Utils.isFastClicker()) {
                    return;
                }
                Bundle bundle = new Bundle();
                bundle.putInt("havesn", messageHTApt.getItem(position).getSn());
                bundle.putLong("havecreation", messageHTApt.getItem(position).getCreationDate());
                bundle.putInt("haveqpsn", messageHTApt.getItem(position).getQpSn());
                bundle.putString("haveqptName", messageHTApt.getItem(position).getQptName());
                bundle.putString("haveqpName", messageHTApt.getItem(position).getQpName());
                bundle.putInt("havetotalScore", messageHTApt.getItem(position).getTotalScore());
                bundle.putInt("havepassScore", messageHTApt.getItem(position).getPassScore());
                bundle.putInt("havescore", messageHTApt.getItem(position).getScore());
                bundle.putInt("havepassMark", messageHTApt.getItem(position).getPassMark());
                bundle.putLong("testEndDate", messageHTApt.getItem(position).getTestEndDate());
                bundle.putString("signPicUrl", messageHTApt.getItem(position).getSignPicUrl());

                /**
                 * 此处要传这条已考的所有数据
                 */
                startActivity(HaveTestActivity.class, bundle);


            }
        });
    }

    @Override
    public void requestData() {
        Bundle bundle = getIntent().getExtras();
        String orgId = bundle.getString("orgId");
        LoginUserBean userInfo = UserManger.getUserInfo();
        LoginUserBean.DataBean data = userInfo.getData();
        String userId = data.getUserId();
        new Login().getDaikaoAndHave(userId, orgId, 0,1,1,10000, this, 2);//已考
    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        if (what == 2) {
            HaveTestBean haveTestBean = JSON.parseObject(result, HaveTestBean.class);
            List<HaveTestBean.RowsBean> havetestrows = haveTestBean.getRows();
            messageHTApt = new HaveTestAdapter(OnlineEducationRecordActivity.this, havetestrows, R.layout.havetest_item);
            listview_havetest.setAdapter(messageHTApt);
        }
        super.onSuccess(result, call, response, what);
    }
}
